#include <stdio.h>
#include <string.h>

void Exchange(char *str, int len)//len记住单词末尾
{
    for(int i = 0; i < len / 2; i++)
    {
        char temp = str[i];
        str[i] = str[len - i - 1];
        str[len - i - 1] = temp;
    }
}

void Exchange2(char * str, int len)
{
    int size = 0;
    for(int i = 0; i < len; i++)
    {
        if(str[i] == ' ' || str[i] == '\0')
        {
            Exchange(str + i - size,size);
            size = 0;
        }
        else
        {
            size++;
        }
    }
}
int main()
{
    char str[] = "i am from nanjing";
    Exchange(str, strlen(str));
    Exchange2(str, strlen(str));
    printf("%s\n",str);
    return 0;
}